<html>
<head>
	<title>CS633 Group Project :: Team 1 :: Address Book</title>
	<link rel="stylesheet" href="css/style.css" type="text/css">
	<script src="js/prototype.js" type="text/javascript"></script>
	<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
	<script src="js/jquery.maskedinput-1.2.2.min.js" type="text/javascript"></script>
	<script src="js/functions.js" type="text/javascript"></script>
	
	<script type="text/javascript">
		jQuery(function($)
		{
		   	$("#phone").mask("(999) 999-9999", {placeholder:" "});
		   	$("#state").mask("aa", {placeholder:" "});
		   	$("#zip").mask("99999", {placeholder:" "});
		});
		
		function validate()
		{
			var frm = window.document.forms[0];
			
			/* Last name */
			if(frm.lname.value.trim().length == 0)
			{
				alert('Please provide the last name.');
				frm.lname.focus();
				return false;
			}
			else
			{
				if(!isName(frm.lname.value.trim()))
				{
					alert('The last name should contain only alphabetical and space characters.');
					frm.lname.focus();
					frm.lname.select();
					return false;
				}
			}
			
			/* First name */
			if(frm.fname.value.trim().length == 0)
			{
				alert('Please provide the first name.');
				frm.fname.focus();
				return false;
			}
			else
			{
				if(!isName(frm.fname.value.trim()))
				{
					alert('The first name should contain only alphabetical and space characters.');
					frm.fname.focus();
					frm.fname.select();
					return false;
				}
			}
			
			/* Street address */
			if(frm.address.value.trim().length == 0)
			{
				alert('Please provide the address.');
				frm.address.focus();
				return false;
			}
			else
			{
				if(!isStreetAddress(frm.address.value.trim()))
				{
					alert('The street address should contain only alphanumeric, hyphen, underscore, period, #, and space characters.');
					frm.address.focus();
					frm.address.select();
					return false;
				}
			}

			/* City */			
			if(frm.city.value.trim().length == 0)
			{
				alert('Please provide the city.');
				frm.city.focus();
				return false;
			}
			else
			{
				if(!isStreetAddress(frm.city.value.trim()))
				{
					alert('The city should contain only alphanumeric, hyphen, underscore, period, #, and space characters.');
					frm.city.focus();
					frm.city.select();
					return false;
				}
			}

			/* State */
			if(frm.state.value.trim().length != 2)
			{
				alert('Please provide the state.');
				frm.state.focus();
				return false;
			}
			else
			{
				if(!isStateCode(frm.state.value.trim()))
				{
					alert('The state should contain a valid US State code. Example: NY');
					frm.state.focus();
					frm.state.select();
					return false;
				}
			}
			
			/* Zip Code */
			if(frm.zip.value.trim().length != 5)
			{
				alert('Please provide the zip code.');
				frm.zip.focus();
				return false;
			}
			
			/* Phone number */
			if(frm.phone.value.trim().length < 14)
			{
				alert('Please provide a valid phone number.');
				frm.phone.focus();
				frm.phone.select();
				return false;
			}
			
			/* E-mail */
			if(!isEmail(frm.email.value.trim()))
			{
				alert('Please provide a valid e-mail address.');
				frm.email.focus();
				return false;
			}
			else
			{
				if(!isEmailAddress(frm.email.value.trim()))
				{
					alert('The e-mail should contain only alphanumeric, hyphen, underscore, period, #, @, and space characters.');
					frm.email.focus();
					frm.email.select();
					return false;
				}
			}
			
			return true;
		}	
	</script>
</head>
<body>
	<table width="100%">
		<!-- HEADER -->
		<tr style="padding:0px">
			<td><!--#include file ="header.asp"--></td>
		</tr>
		
		<!-- BODY -->
		<tr>
			<td align="center">
				<form name="NewEntry" method="post" action="action_add.asp">
				<table bgcolor=#990000 width=1000 cellpadding=5 cellspacing=1 border=0>
					<tr class="header">
						<td colspan=2>Add New Entry
					<tr class="oddrow">
						<td width=200>Last Name
						<td><input id="lname" type="text" name="lname" size=25 maxlength="25">
					<tr class="evenrow">
						<td width=200>First Name
						<td><input id="fname" type="text" name="fname" size=25 maxlength="25">
					<tr class="oddrow"> 
						<td width=200>Address
						<td><input id="address" type="text" name="address" size=25 maxlength="50">
					<tr class="evenrow">
						<td width=200>City
						<td><input id="city" type="text" name="city" size=25 maxlength="26">
					<tr class="oddrow">
						<td width=200>State
						<td>
						
						<!--
						<input id="state" type="text" name="state" maxlength="2" size="2" onblur="this.value = this.value.toUpperCase();">
						// -->
						
						<select name="state">
							<option value="" selected>---</option>
							<option value="AL">AL</option>
							<option value="AK">AK</option>
							<option value="AZ">AZ</option>
							<option value="AR">AR</option>
							<option value="CA">CA</option>
							<option value="CO">CO</option>
							<option value="CT">CT</option>
							<option value="DE">DE</option>
							<option value="DC">DC</option>
							<option value="FL">FL</option>
							<option value="GA">GA</option>
							<option value="HI">HI</option>
							<option value="ID">ID</option>
							<option value="IL">IL</option>
							<option value="IN">IN</option>
							<option value="IA">IA</option>
							<option value="KS">KS</option>
							<option value="KY">KY</option>
							<option value="LA">LA</option>
							<option value="ME">ME</option>
							<option value="MD">MD</option>
							<option value="MA">MA</option>
							<option value="MI">MI</option>
							<option value="MN">MN</option>
							<option value="MS">MS</option>
							<option value="MO">MO</option>
							<option value="MT">MT</option>
							<option value="NE">NE</option>
							<option value="NV">NV</option>
							<option value="NH">NH</option>
							<option value="NJ">NJ</option>
							<option value="NM">NM</option>
							<option value="NY">NY</option>
							<option value="NC">NC</option>
							<option value="ND">ND</option>
							<option value="OH">OH</option>
							<option value="OK">OK</option>
							<option value="OR">OR</option>
							<option value="PA">PA</option>
							<option value="RI">RI</option>
							<option value="SC">SC</option>
							<option value="SD">SD</option>
							<option value="TN">TN</option>
							<option value="TX">TX</option>
							<option value="UT">UT</option>
							<option value="VT">VT</option>
							<option value="VA">VA</option>
							<option value="WA">WA</option>
							<option value="WV">WV</option>
							<option value="WI">WI</option>
							<option value="WY">WY</option>
						</select>
						
					<tr class="evenrow">
						<td width=200>Zip
						<td><input id="zip" type="text" name="zip" maxlength="5" size=5>
					<tr class="oddrow">
						<td width=200>Phone
						<td><input id="phone" type="text" name="phone" size=20>
					<tr class="evenrow">
						<td width=200>E-mail
						<td><input id="email" type="text" name="email" maxlength="50" size=25>
					<tr class="oddrow">
						<td width=200>
						<td><input type="button" onclick="history.go(-1);" value="&lt&lt Back" />&nbsp;&nbsp;
						<input type="submit" onclick="return validate();" value="Publish Entry">&nbsp;&nbsp;	<input type="reset" value="Reset">
				</table>
				</form>
			</td>
		</tr>
		
		<!-- FOOTER -->
		<tr style="padding:0px">
			<td><!--#include file ="footer.asp"--></td>
		</tr>			
	</table>
</body>